<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">修改用户信息</h3>
                </div>
                <form id="userAlert" class="form-horizontal" role="form">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="userName" class="col-sm-2 control-label">用户名：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="userName" class="form-control" name="userName"
                                     value="${obj.userName}"  placeholder="用户名" >
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="passWord" class="col-sm-2 control-label">密码：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="passWord" class="form-control" name="passWord"
                                      value="${obj.passWord}" placeholder="密码" >
                            </div>
                        </div>
                        <br>
                             <div class="form-group">
                            <label for="mail" class="col-sm-2 control-label">商务姓名：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="businessName" class="form-control" name="businessName"
                                      value="${obj.businessName}" placeholder="商务姓名">
                            </div>
                        </div>
                        <br>
                             <div class="form-group">
                            <label for="mail" class="col-sm-2 control-label">邮箱：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="mail" class="form-control" name="mail"
                                      value="${obj.mail}" placeholder="邮箱">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="mail" class="col-sm-2 control-label">邮箱密码：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="mailPassWord" class="form-control" name="mailPassWord"
                                       value="${obj.mailPassWord}" placeholder="邮箱密码">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="state" class="col-sm-1 control-label">权限：</label>
							  <div class="col-sm-8 ">
                             <select id="roleId" name="roleId" class="form-control select2" >
                               	<option value="1">管理员</option>
                                <option value="2">商务</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="state" class="col-sm-1 control-label">状态：</label>
							  <div class="col-sm-8 ">
                             <select id="state" name="state" class="form-control select2" >
                               	<option value="1">有效</option>
                                <option value="2">无效</option>
                             </select>
                             </div>
                        </div>
                        <br>
                         <input type="hidden" readonly="readonly" id="id"  name="id" value="${obj.id}">
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
var state = ${obj.state};
var roleId = ${obj.roleId};
    $(function () {
    	//初始化下拉框默认值
    	document.getElementById("state").value = state;
    	document.getElementById("roleId").value = roleId;
        $('#userAlert').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                userName: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        },
                        threshold: 2, //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                        remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值，获得一个json数据。例表示正确：{"valid",true}
                            url: '<%=path%>/user/checkUserName',//验证地址
                            message: '用户名已存在',//提示消息
                            delay: 2000,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
                            type: 'POST',//请求方式
                            data: function (validator) {
                                return {
                                	userName: $('#userName').val(),
									id: $('#id').val()                                	
                                };
                            }
                        },
                    }
                },
                passWord: {
                    message: '密码验证失败',
                    validators: {
                        notEmpty: {
                            message: '密码不能为空'
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            save();
        });
    });

    function save() {
        $.post("<%=path%>/user/updateUser",
            $("#userAlert").serialize()
            , function (data) {
                if (data.missage == "success") {
                    modalMsg("修改成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "error"){
                	 modalMsg("修改失败", "error");
                }else{
                	 modalMsg("更新失败", "error");
                }

            }
        );
    }
    
</script>
</body>
</html>